﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL_NhaSach;
using BLL;

namespace BLL_NhaSach
{
    public class CTPhieuNhapBLL : IProcessData
    {
        QLNhaSachEntities db;
        public CTPhieuNhapBLL(String cnStr)
        {
            db = new QLNhaSachEntities(cnStr);
        }
        public object getAllData()
        {
            return (from ct in db.ChiTietPhieuNhaps select new {ct.MaPhieuNhap,ct.Sach.TenSach,ct.SoLuong,ct.DonGia });
        }

        public object findObjects(string find_content)
        {
            return db.ChiTietPhieuNhaps.SingleOrDefault(p => p.MaSach.Equals(find_content));
        }

        public object findObjects(int find_content)
        {
            return db.ChiTietPhieuNhaps.SingleOrDefault(p => p.MaPhieuNhap == find_content);
        }

        public object sort(string Col_Name, bool state)
        {
            throw new NotImplementedException();
        }

        public bool addObject(object addObj)
        {
            ChiTietPhieuNhap ct = (ChiTietPhieuNhap)addObj;
            try
            {
                db.ChiTietPhieuNhaps.AddObject(ct);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool deleteObject(int id)
        {
            throw new NotImplementedException();
        }
        public bool deleteObject(String id)
        {
            ChiTietPhieuNhap ct = db.ChiTietPhieuNhaps.SingleOrDefault(p => p.MaSach.Equals(id));
            if (ct != null)
            {
                db.ChiTietPhieuNhaps.DeleteObject(ct);
                try
                {
                    db.SaveChanges();
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
            else return false;
        }
        public bool updateObject(object updateObj)
        {
            throw new NotImplementedException();
        }
    }
}
